package cn.gjxblog.aop.proxy.cglib;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 实现了MethodInterceptor拦截器
 *
 * @Author guojiaxun
 * @Date 2020/3/9 10:45
 */
public class MyInterceptor implements MethodInterceptor {

    UserServiceImpl userService;


    public MyInterceptor(UserServiceImpl userService) {
        this.userService = userService;
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("方法执行前----------");
        System.out.println(o.getClass());
        System.out.println(methodProxy.getClass());
       return  methodProxy.invoke(userService,objects);
    }
}
